package com.baosight.sczx.common.zm.cInterface.cl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 三违记录
 * <p>Title: TernateDeregulation.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-11-17 上午06:19:33  严洪浩  Create
 *</pre>
 */
public class TernateDeregulation {		
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 作废罚款记录时
	 * 更新三违数据
	 * <p>Function: UpdatePenalty</p>
	 * <p>Description: </p>
	 * <p>return value:int</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-13下午03:50:24 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static int UpdatePenalty(String fdPenaltyId) {
		int count = 0;
		Map<String, String> _argMap = new HashMap<String, String>();
		_argMap.put("fdPenaltyId", fdPenaltyId);
		
		List<Map> _list = dao.query("ZMCLTernateRecord.queryInvalidPenalty", _argMap);
		if(_list.size() > 0) {
			Map _map = _list.get(0);
			
			String fdTernateDeregulationId = _map.get("fdKeyId") == null ? "" : _map.get("fdKeyId").toString();
			String fdIsPenalty = _map.get("fdIsPenalty") == null ? "" : _map.get("fdIsPenalty").toString();
			
			if(!"".equals(fdIsPenalty) && !"否".equals(fdIsPenalty)) {
				int number = 0;
				try {
					String _number = fdIsPenalty.substring(fdIsPenalty.indexOf("(")+1, fdIsPenalty.indexOf(")"));
					number = Integer.parseInt(_number) - 1;
				} catch (NumberFormatException e) {
					System.out.println("作废罚款记录时更新三违数据异常: " + e.getMessage());
				}
				if(number <= 0) {
					fdIsPenalty = "否";
				}
				else {
					fdIsPenalty = "是("+number+")";
				}
				Map<String, String> _upArgs = new HashMap<String, String>();
				_upArgs.put("fdKeyId", fdTernateDeregulationId);
				_upArgs.put("fdIsPenalty", fdIsPenalty);
				
				count = dao.update("ZMCLTernateRecord.updateInvalidPenalty", _upArgs);
			}
		}
		
		return count;
	}
}